package com.hardydou.system.model;

import com.hardydou.common.constant.Const.UserStatus;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;

/**
 * @author ：hardy
 * @description：登录用户信息
 * @date ：Created in 2020-03-04
 * @Copyright ：Hardydou.com
 */
public class LoginUserDetails implements Serializable, UserDetails {


    private SystemUser systemUser;

    public LoginUserDetails(SystemUser systemUser) {
        this.systemUser = systemUser;
    }

    public SystemUser getSystemUser() {
        return systemUser;
    }

    public void setSystemUser(SystemUser systemUser) {
        this.systemUser = systemUser;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return systemUser.getResList();
    }

    @Override
    public String getPassword() {
        return systemUser.getPassword();
    }

    @Override
    public String getUsername() {
        return systemUser.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return systemUser.getStatus() != UserStatus.LOCKED.val;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return systemUser.getStatus() == UserStatus.NORMAL.val;
    }
}
